package com.oasystem.domain;

import java.util.ArrayList;
import java.util.List;

public class PagingBean<T> {
	private int pageSize = 5;
	private int allRecordCount = 0;
	private int currentPage = 1;
	private int previousPage = 1;
	private int nextPage = 1;
	private List<T> data = new ArrayList<T>();

	public int getAfterDeletePage() {
		if (currentPage < getTotalPages()) {
			return currentPage;
		} else if (allRecordCount % pageSize == 1 && allRecordCount > pageSize) {
			return currentPage - 1;
		} else if (allRecordCount % pageSize != 1 && allRecordCount > pageSize) {
			return currentPage;
		} else {
			return 1;
		}
	}

	public void setAfterDeletePage(int afterDeletePage) {
	}

	public int getPreviousPage() {
		return previousPage;
	}

	public void setPreviousPage(int previousPage) {
		this.previousPage = previousPage;
	}

	public int getNextPage() {
		return nextPage;
	}

	public void setNextPage(int nextPage) {
		this.nextPage = nextPage;
	}

	public boolean isHasNextPage() {
		return currentPage < getTotalPages();
	}

	public void setHasNextPage(boolean hasNextPage) {
	}

	public boolean isHasPreviousPage() {
		return 1 < currentPage;
	}

	public void setHasPreviousPage(boolean hasPreviousPage) {
	}

	public List<String> getPageIndexList() {
		List<String> list = new ArrayList<String>();
		int totalPages = getTotalPages();
		for (int i = 1; i <= totalPages; i++) {
			list.add(String.valueOf(i));
		}
		return list;
	}

	public void setPageIndexList(List<String> list) {

	}

	public int getTotalPages() {
		int tmp = allRecordCount % pageSize;
		return tmp > 0 ? allRecordCount / pageSize + 1 : allRecordCount
				/ pageSize;
	}

	public void setTotalPages(int totalPages) {
	}

	public int getCurrentRecordIndex() {
		return (currentPage - 1) * pageSize;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getAllRecordCount() {
		return allRecordCount;
	}

	public void setAllRecordCount(int allRecordCount) {
		this.allRecordCount = allRecordCount;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		previousPage = currentPage - 1 > 0 ? currentPage - 1 : 1;
		nextPage = currentPage + 1;
		this.currentPage = currentPage;
	}

	public List<T> getData() {
		return data;
	}

	public void setData(List<T> data) {
		this.data = data;
	}

}
